# 划分字母区间

class Solution:

    def partitionLabels(self, s):
        # 存储每一个字母对应的索引
        dic = {a: index for index, a in enumerate(s)}
        num = 0
        result = []
        j = dic[s[0]] # 找到第一个字母的最后位置

        for i in range(len(s)):
            num += 1
            if dic[s[i]] > j:
                j = dic[s[i]]

            if i == j:
                result.append(num)
                num = 0
            
        return result
    

if __name__ == "__main__":

    s = "ababcbacadefegdehijhklij"
    sol = Solution()
    res = sol.partitionLabels(s)
    print(res)
